package com.dd.common.config;

import com.dd.common.utils.YmlUtils;

import java.io.File;

/**
 * 全局配置
 */
public class GlobalConfig {

    // UTF-8
    public static final String UTF8 = "UTF-8";

    // 默认密码
    public static final String DEFAULT_PASSWORD = "123456";

    // 当前用户 key
    public static final String CURRENT_USER = "current_user";

    // 密钥
    public static final String secret = "protect_the_best_kun_kun";

    // 状态值 0禁用
    public static final Integer STATUS_DISABLE = 0;
    // 状态值 1启用
    public static final Integer STATUS_ENABLE = 1;

    // 项目上下文路径
    public static String contextPath = YmlUtils.get("server.servlet.context-path", "");

    // Mysql表前缀
    public static String tablePrefix = "c_";

    // Redis键前缀
    public static String redisPrefix = "like:";

    // 资源访问前缀
    public static String publicPrefix = "fetch/file";

    // 文件存储路径（默认为项目根目录下的files文件夹）
    // user.dir是JVM启动位置（通常为项目根目录）
    // File.separator 系统文件分隔符，windows下为“\”，linux下为“/”
    private static final String fileSavePathDefaultValue = System.getProperty("user.dir") + File.separator + "files" + File.separator;
    private static final String LOCALSTORAGE_ROOT_DIR_CONFIG_KEY = "ikun.storage.local.savedRootDir";
    // YmlUtils工具类设置的默认值，无法在空字符串的情况（设置了配置字段但没设置值）下生效，只会在null时生效（未添加配置字段）
    private static final String configValue = YmlUtils.get(LOCALSTORAGE_ROOT_DIR_CONFIG_KEY, fileSavePathDefaultValue);
    public static String fileSavePath = "".equals(configValue) ? fileSavePathDefaultValue : configValue;

    // 上传图片限制 (10M)
    public static Integer uploadImageSize = 1024 * 1024 * 10;

    // 上传视频限制 (30M)
    public static Integer uploadVideoSize = 1024 * 1024 * 30;

    // 上传图片后缀
    public static String[] uploadImageExt = new String[]{"png", "jpg", "jpeg", "gif", "ico", "bmp", "svg", "webp"};
    // 上传图片后缀对应的MIME类型
    public static String[] uploadImageMimeTypes = new String[]{
            "image/png",          // png
            "image/jpeg",         // jpg, jpeg
            "image/gif",          // gif
            "image/x-icon",       // ico
            "image/bmp",          // bmp
            "image/svg+xml",      // svg
            "image/webp"          // webp
    };

    // 上传视频后缀
    public static String[] uploadVideoExt = new String[]{"mp4", "avi", "flv", "rmvb", "mov", "wmv", "mkv", "3gp", "m4v"};
    // 上传视频后缀对应的MIME类型
    public static String[] uploadVideoMimeTypes = new String[]{
            "video/mp4",          // mp4
            "video/x-msvideo",    // avi
            "video/x-flv",        // flv
            "video/vnd.rn-realvideo", // rmvb
            "video/quicktime",    // mov
            "video/x-ms-wmv",     // wmv
            "video/x-matroska",   // mkv
            "video/3gpp",         // 3gp
            "video/x-m4v"         // m4v
    };
    // 上传音频后缀
    public static String[] uploadAudioExt = new String[]{"mp3", "wav", "wma", "aac", "flac", "ape", "m4a", "ogg", "oga", "ac3"};
    // 上传音频MIME
    public static String[] uploadAudioMimeTypes = new String[]{
            "audio/mpeg",         // mp3
            "audio/wav",          // wav
            "audio/x-ms-wma",     // wma
            "audio/aac",          // aac
            "audio/flac",         // flac
            "audio/ape",          // ape (常用自定义类型)
            "audio/mp4",          // m4a
            "audio/ogg",          // ogg, oga
            "audio/ac3"           // ac3
    };
    // 上传文档后缀
    public static String[] uploadDocExt = new String[]{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf", "txt", "md", "xml", "html", "htm"};
    // 上传文档MIME类型
    public static String[] uploadDocMimeTypes = new String[]{
            // Office文档
            "application/msword", // doc
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document", // docx
            "application/vnd.ms-excel", // xls
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // xlsx
            "application/vnd.ms-powerpoint", // ppt
            "application/vnd.openxmlformats-officedocument.presentationml.presentation", // pptx

            // 通用文档
            "application/pdf",    // pdf
            "text/plain",         // txt
            "text/markdown",      // md (常用自定义类型)

            // 标记语言
            "application/xml",    // xml
            "text/html",          // html, htm
            "text/css"            // css (补充)
    };
}
